// pages/user/appraise/appraise.js
const app = getApp();
let api = require('../../../utils/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appraise:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // var that=this;
    // var appraiseData = that.data.appraise;
    //// console.log(that.data.appraise);
    // for (var i = 0; i < appraiseData.length;i++){
    //   switch (appraiseData[i]['appraise']){
    //     case '好评':
    //       appraiseData[i]['appraise'] = '../../../../../../../public/img/positive-choose.png';
    //       break;

    //     case '中评':
    //       appraiseData[i]['appraise'] = '../../../../../../../public/img/moderate.png';
    //       break;
    //     case '差评':
    //       appraiseData[i]['appraise'] = '../../../../../../../public/img/negative.png';
    //       break;
    //   }
    // }
    // this.setData({
    //   appraise: appraiseData
    // })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this;
    var token=wx.getStorageSync('TOKEN');
    var param = {
      // pageNum: 1,
      // pageSize: 5
    }
    var appraise = [];
    appraise[3] = '好评';
    appraise[2] = '中评';
    appraise[1] = '差评';
    api._get('/user/evaluate/list', param, token).then(res => {
      if (res.code == 200) {

        var list = res.result.evaluates;
        if (list){
          list.forEach(function (value, index) {
            var createTime = value.createTime * 1000;
            list[index]['showCreateTime'] = app.formatDate(createTime, 'YYYY-MM-DD');
            list[index]['showStar'] = appraise[value.star];
          });
        }
        that.setData({
          appraise: list,
          "star1Total": res.result.star1Total,
          "star2Total": res.result.star2Total,
          "star3Total": res.result.star3Total,
          "starRatio": res.result.starRatio
        });

      } else if (res.code > 400) {
        wx.navigateTo({
          url: '../login/login',
        })
      } else {
        wx.showToast({
          title: '网络忙请重试',
          icon: 'none',
        })
      }

    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})